<?php
// +----------------------------------------------------------------------
// | 会员卡列表
// +----------------------------------------------------------------------
// | Author: TongBC <501468940@qq.com>
// +----------------------------------------------------------------------
// | Date  : 2015/05/25
// +----------------------------------------------------------------------
ob_start();
include_once '/var/www/html/new/d/common/header.html';
include_once '/var/www/html/new/d/common/left.html';
include_once '/var/www/html/new/d/common/func.inc.php';
include_once '/var/www/html/new/d/class/SimpleExcel.class.php';
$out_html = ob_get_contents();
ob_end_clean();




// 数据导出
if(isset($_REQUEST['act']) && $_REQUEST['act']=='loadExcel'){
	// 搜索条件
	$memberSID = $_SESSION['sid'];
	$where = "where c.apply_did=$memberSID";
	if(isset($_REQUEST['status']) && $_REQUEST['status']!=''){
		 $where.=' and mc.status='.($_REQUEST['status']+0);
	}else{
		 $where.=' and mc.status<4';
	}

	if(isset($_REQUEST['keyword']) && $_REQUEST['keyword']!=''){
		// $keyword = $_REQUEST['keyword'] + 0;
		$keyword = $_REQUEST['keyword'];
		if(abc777\Validate::isMobile($_REQUEST['keyword'])){// 手机号
			$where.=" and m.mobile='$keyword'";
		}elseif(is_numeric($_REQUEST['keyword'])){
			$where.=" and mc.card_no='$keyword'";
		}else{
			$where.=" and m.dname='$keyword' or m.cname='$keyword'";
		}
	}
	
	
	// 获取已配置的分销商
	$memberCard = array();
	$sql = "select m.dname,m.cname,m.id as did,m.mobile,c.daily_buy_limit,c.buy_interval,c.buy_num_limit,mc.status,mc.card_no,mc.id as cid,c.id as config_id,mc.card_time from pft_card_consume_conf c left join pft_member m on m.id=c.memberID left join pft_member_card mc on c.card_id=mc.id $where"; 
	$GLOBALS['le']->query($sql);
	while($row=$GLOBALS['le']->fetch_assoc()) $memberCard[] = $row;

	
	$status_t = array('正常','挂失','禁用','冻结','废弃');
	
	$Excel = array();
	$Excel[0][] = '会员名称';
	$Excel[0][] = '会员卡号';
	$Excel[0][] = '开卡时间';
	$Excel[0][] = '状态';
	$i=1;
	foreach($memberCard as $row){
		$Excel[$i][] = $row['dname'];
		$Excel[$i][] = $row['card_no'];
		$Excel[$i][] = $row['card_time'];
		$Excel[$i][] = $status_t[$row['status']];
		$i++ ;
	}
	$xls = new SimpleExcel('UTF-8', true,'会员卡列表');
	$xls->addArray($Excel);
	$xls->generateXML('会员卡列表');
	exit;
}









echo $out_html;

include('/var/www/html/new/d/tpl/membercard/mem_list.html');
include('/var/www/html/new/d/common/footer.html');
